package com.newx.file.template.impl;

import cn.hutool.core.lang.Assert;
import com.newx.file.config.NewxFileConfig;
import com.newx.file.param.TencentFileUploadParam;
import com.newx.file.template.AbstractFileApiTemplate;
import com.newx.file.util.FileUploadUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author yxl
 * @date 2024/7/22 0022 15:14
 */
@Service
@Slf4j
@AllArgsConstructor
public class TencentFileApiTemplateImpl extends AbstractFileApiTemplate {

    private NewxFileConfig newxFileConfig;
    @Override
    public Object uploadFile(MultipartFile file) {
        Assert.notBlank(newxFileConfig.getTencentBucketName(), "腾讯云bucketName不能为空");
        Assert.notBlank(newxFileConfig.getTencentRegion(), "腾讯云region不能为空");
        Assert.notBlank(newxFileConfig.getTencentSecretId(), "腾讯云SecretId不能为空");
        Assert.notBlank(newxFileConfig.getTencentSecretKey(), "腾讯云SecretKey不能为空");
        Assert.notNull(newxFileConfig.getTencentPackagePath(), "腾讯云packagePath不能为空");
        TencentFileUploadParam param = new TencentFileUploadParam()
                .setBucketName(newxFileConfig.getTencentBucketName())
                .setRegion(newxFileConfig.getTencentRegion())
                .setSecretId(newxFileConfig.getTencentSecretId())
                .setSecretKey(newxFileConfig.getTencentSecretKey())
                .setPackagePath(newxFileConfig.getTencentPackagePath())
                .setFile(file);
        return FileUploadUtil.uploadTencentFile(param);
    }
}
